package com.pro.controller;

import com.pro.mapper.JsBeforeUserMapper;
import com.pro.pojo.JsBeforeUser;
import com.pro.pojo.JsClosure;
import com.pro.pojo.JsUnseal;
import com.pro.pojo.JsonData;
import com.pro.service.JsBeforeUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * ClassName:JsBeforeUserController
 * Package:com.pro.controller
 * Description:
 *
 * @Date:2022/1/21 15:08
 * @Author: XJR
 */
@RequestMapping("/beforeUser")
@RestController
public class JsBeforeUserController {

    @Autowired
    private JsBeforeUserService service;

    private JsClosure jsClosures = new JsClosure();

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/21
     * @Content:进思用户人员列表
     */
    @RequestMapping("/selectJsBeforeUser")
    public JsonData selectJsBeforeUser(String userCode, String account, String fullName, String profession,Integer limit,Integer page){
        List<JsBeforeUser> jsBeforeUsers = service.selectJsBeforeUser(userCode, account, fullName, profession,limit,page);
        Integer count = service.countJsBeforeUser(userCode, account, fullName, profession);
        return jsBeforeUsers!=null?JsonData.buildSuccess(jsBeforeUsers,count):JsonData.buildError("服务端发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/21
     * @Content:通过id查看信息详情
     */
    @RequestMapping("/selectJsBeforeUserById")
    public JsonData selectJsBeforeUserById(Integer userId){
        List<JsBeforeUser> jsBeforeUsers = service.selectJsBeforeUserById(userId);
        return jsBeforeUsers!=null?JsonData.buildSuccess(jsBeforeUsers):JsonData.buildError("服务端发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/21
     * @Content:更改用户毕业状态
     */
    @RequestMapping("/beforeUserType")
    public JsonData beforeUserType(Integer userId,Integer type){
        Boolean tyBoolean = service.beforeUserType(userId, type);
        return tyBoolean!=false?JsonData.buildSuccess(tyBoolean):JsonData.buildError("服务端发生错误");
    };



    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/21
     * @Content:更改用户账号状态
     */
    @RequestMapping("/beforeUserAccount")
    public JsonData beforeUserAccount(JsClosure jsClosure){
        Boolean aBoolean;
        Boolean statusBoolean;
        if(jsClosure.getStatus()==5){
            jsClosure.setRemarks("强制封停");
            aBoolean = service.insertUserClosure(jsClosure);
            jsClosures.setIdd(jsClosure.getIdd());
            statusBoolean = service.beforeUserAccount(jsClosure);
        }else{
            JsUnseal jsUnseal = new JsUnseal();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            Date parse=new Date();
            try{
               parse = sdf.parse(jsClosure.getStartDatee());
            }catch (ParseException e){
                e.printStackTrace();
            }
            jsUnseal.setUserId(jsClosure.getId());
            jsUnseal.setType(jsClosure.getType());
            jsUnseal.setUnsealDate(parse);
            jsUnseal.setRemarks("强制解封");
            aBoolean = service.insertUserUnseal(jsUnseal);
            Boolean aBoolean1 = service.updateUserClosure(jsClosures.getIdd(), jsClosure.getStartDatee());
            statusBoolean = service.beforeUserAccount(jsClosure);
        }
        return aBoolean!=false&&statusBoolean!=false?JsonData.buildSuccess(aBoolean):JsonData.buildError("服务端发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/21
     * @Content:编辑用户信息
     */
    @RequestMapping("/updateBeforeUser")
    public JsonData updateBeforeUser(JsBeforeUser jsBeforeUser){
        JsBeforeUser jsBeforeUser1 = new JsBeforeUser();
        jsBeforeUser1.setAccount(jsBeforeUser.getAccount());
        jsBeforeUser1.setCreateDate(jsBeforeUser.getCreateDate());
        jsBeforeUser1.setEmail(jsBeforeUser.getEmail());
        jsBeforeUser1.setFreestyle(jsBeforeUser.getFreestyle());
        jsBeforeUser1.setFullName(jsBeforeUser.getFullName());
        jsBeforeUser1.setIdCard(jsBeforeUser.getIdCard());
        jsBeforeUser1.setNickname(jsBeforeUser.getNickname());
        jsBeforeUser1.setPhone(jsBeforeUser.getPhone());
        jsBeforeUser1.setSex(jsBeforeUser.getSex());
        jsBeforeUser1.setStudyDate(jsBeforeUser.getStudyDate());
        jsBeforeUser1.setUserId(jsBeforeUser.getUserId());
        jsBeforeUser1.setConsumption(jsBeforeUser.getConsumption());
        jsBeforeUser1.setUserCode(jsBeforeUser.getUserCode());
        jsBeforeUser1.setAvatarUrl(jsBeforeUser.getAvatarUrl());
        JsBeforeUser jsBeforeUser2 = new JsBeforeUser();
        jsBeforeUser2.setCreateDate(jsBeforeUser.getCreateDate());
        jsBeforeUser2.setEntranceDate(jsBeforeUser.getEntranceDate());
        jsBeforeUser2.setGraduationDate(jsBeforeUser.getGraduationDate());
        jsBeforeUser2.setIntegration(jsBeforeUser.getIntegration());
        jsBeforeUser2.setProfession(jsBeforeUser.getProfession());
        jsBeforeUser2.setUserId(jsBeforeUser.getUserId());
        Boolean updateBoolean = service.updateBeforeUser(jsBeforeUser1);
        Boolean updateaBoolean = service.updateUserDevelopment(jsBeforeUser2);
        return updateBoolean!=false&&updateaBoolean!=false?JsonData.buildSuccess(updateBoolean):JsonData.buildError("服务端发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/22
     * @Content:查看非进思用户信息
     */
    @RequestMapping("/selectNoUserBefore")
    public JsonData selectNoUserBefore(String account,String nickName,String createDate,Integer limit,Integer page){
        List<JsBeforeUser> jsBeforeUsers = service.selectNoUserBefore(account, nickName, createDate,limit,page);

        return jsBeforeUsers!=null?JsonData.buildSuccess(jsBeforeUsers):JsonData.buildError("服务端发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/22
     * @Content:查看非进思用户信息详情
     */
    @RequestMapping("/selectNoJsBeforeUserById")
    public JsonData selectNoJsBeforeUserById(Integer userId){
        JsBeforeUser jsBeforeUser = service.selectNoJsBeforeUserById(userId);
        return jsBeforeUser!=null?JsonData.buildSuccess(jsBeforeUser):JsonData.buildError("服务端发生错误");
    };

    //对后台用户账户进行封停
    @RequestMapping("/insertUserClosure")
    public JsonData insertUserClosure(JsClosure jsClosure){
        Boolean aBoolean1 = service.updateUserStatus(jsClosure.getId(), jsClosure.getStatus());
        Boolean aBoolean = service.insertUserClosure(jsClosure);
        return aBoolean1!=false&&aBoolean!=false?JsonData.buildSuccess(aBoolean1): JsonData.buildError("服务端错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/23
     * @Content:零消费用户列表
     */
    @RequestMapping("/selectZeroUser")
    public JsonData selectZeroUser(String account,String nickName,String createDate,Integer limit,Integer page){
        List<JsBeforeUser> jsBeforeUsers = service.selectZeroUser(account, nickName, createDate, limit, page);
        Integer count = service.countZeroUser(account, nickName, createDate);
        return jsBeforeUsers!=null?JsonData.buildSuccess(jsBeforeUsers,count): JsonData.buildError("服务端错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/2/16
     * @Content:通过id查看零消费用户详细信息
     */
    @RequestMapping("/selectZoreUserById")
    public JsonData selectZoreUserById(Integer userId){
        JsBeforeUser jsBeforeUser = service.selectZoreUserById(userId);
        return jsBeforeUser!=null?JsonData.buildSuccess(jsBeforeUser): JsonData.buildError("服务端错误");
    };
}
